<?php
    #商品详情
    require ("connect.php");
    $name = $_GET['name'];
    $id = $_GET['id'];
    mysqli_set_charset($link, 'utf8') or die('设置编码失败'.mysqli_error());
    $query = "select * from tb_shangpin where id = $id";
    $result = mysqli_query($link, $query) or die('查询失败'.mysqli_error());
    $row = mysqli_fetch_array($result);
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>商品详情-<?php echo $name;?></title>
    <link rel="stylesheet" href="css/details.css">
</head>
<body>
    <div class="main">
        <div class="top">
            <div class="left">
                <img src="<?php echo $row['photo'];?>" alt="" width="350" height="400" />
            </div>

            <div class="right">
                <form action="addGoods.php?id=<?php echo $id;?>" method="get">
                    <input type="hidden" name="id" value="<?php echo $row['id'];?>">
                    <p>
                        VIP价格:<span class="price">￥<?php echo number_format($row['vipPrice'],2);?></span>
                    </p>
                    <p>
                        原价:<span>￥<?php echo number_format($row['price'],2);?></span>
                    </p>
                    <p>
                        品牌:<strong><?php echo $row['brand'];?></strong>
                    </p>
                    <p>
                        产地:<strong><?php echo $row['place'];?></strong>
                    </p>
                    <p>退还承诺:<a href="policy.php">商品的退换货政策</a></p>
                    <?php
                        session_start();
                        if(!isset($_SESSION['car'][$id]['num'])){
                            $num = 0;
                        }else{
                            $num = $_SESSION['car'][$id]['num'];
                        }   
                    ?>
                    购买数量:<input type="number" name="num" min="0" step="1" value="<?php echo $num;?>" /><br>
                    <input type="submit" value="加入购物车" />
                    <a href="shoppingCar.php">
                        <input type="button" value="查看购物车" />
                    </a>
                </form>
            </div>
        </div>
        <div class="bottom">
            <ul>
                <li>商品详情</li>
            </ul>
            <p style="font-size: 2rem;font-weight: bolder;">
                <?php echo $row['introduction'];?>
            </p>
        </div>
    </div>
</body>
</html>
<?php mysqli_close($link);?>